04. Simple Mover
You will now go through the process of implementing your first ROS node in python.
This node is called
simple_mover
. As it’s name implies, this node only has one responsibility, and that is to command joint movements for
simple_arm
.
To do so, it must publish joint angle command messages to the following topics:
|
Topic Name
| /simple_arm/joint_1_position_controller/command |
|-|-|
|
Message Type
| std_msgs/Float64 |
|
Description
| Commands joint 1 to move counter-clockwise, units in radians |
|**Topic Name ** | /simple_arm/joint_2_position_controller/command |
|-|-|
|
Message Type
| std_msgs/Float64 |
|
Description
| Commands joint 2 to move counter-clockwise, units in radians |
Note : If you no longer have the catkin workspace from the previous lesson, you can download a copy of it here . Alternately, If you’d prefer to skip to the punch, you can download the entire, complete simple_arm package from here .
Adding the scripts directory
In order to create a new node in python, you must first create the
scripts
directory within the
simple_arm
package, as it does not yet exist.
$ cd ~/catkin_ws/src/simple_arm/
$ mkdir scripts
Creating a new script
Once the scripts directory has been created, executable scripts can be added to the package. However, in order for
rosrun
to find them, their permissions must be changed to allow execution. Let’s add a simple bash script that prints “Hello World” to the console.
$ cd scripts
$ echo '#!/bin/bash' >> hello
$ echo 'echo Hello World' >> hello
After setting the appropriate execution permissions on the file, rebuilding the workspace, and sourcing the newly created environment, you will be able to run the script.
$ chmod u+x hello
$ cd ~/catkin_ws
$ catkin_make
$ source devel/setup.bash
$ rosrun simple_arm hello
And there you have it! You have now added a script
Creating the empty simple_mover node script
To create the simple_mover node script, you will must simply follow the same basic routine introduced a moment ago.
sh
$ cd ~/catkin_ws/src/simple_arm
$ cd scripts
$ touch simple_mover
$ chmod u+x simple_mover
You can now edit the empty
simple_mover
script with your favorite text editor.
Let’s write the code!